/*==============================================================================
   simple_delay.h
   
   simple delay functions  
   Written by Ervin Jung (2010)

--------------------------------------------------------------------------------

   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 2, or (at your option) any
   later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

   In other words, you are welcome to use, share and improve this program.
   You are forbidden to forbid anyone else to use, share and improve
   what you give them.   Help stamp out software-hoarding!

   As a special exception, if you link this library with other files,
   some of which are compiled with SDCC, to produce an executable,
   this library does not by itself cause the resulting executable
   to be covered by the GNU General Public License.
   This exception does not however invalidate any other reasons why
   the executable file might be covered by the GNU General Public License.
==============================================================================*/

#ifndef __SIMPLE_DELAY_H__
#define __SIMPLE_DELAY_H__

#ifndef FOSC
  #error YOU MUST DEFINE FOSC
#endif

#include <delay.h>

#define __DELAY_CLOCK__   FOSC / 1000000 / 4
#define __DELAY_CLOCK2__ __DELAY_CLOCK__ >> 2

void delay_cycles(unsigned int t) {
  while(t--) {
    __asm
     nop
    __endasm;
  }
}
void delay_us(unsigned int t) {
  t = t >> 2;
  while(t--) {
    delay10tcy(__DELAY_CLOCK2__);
  }
}

void delay_ms(unsigned int t) {
  while(t--) {
    delay1ktcy(__DELAY_CLOCK__ );
  }
}

#endif
